﻿using System;
using System.Web.UI.WebControls;

using SLIITPro.Data.Extension;

namespace SLIITPro.SysUsers
{
    public partial class MyBusiness : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                LoadBusiness();
        }

        private Data.Entity.Users _users;
        private WishListExtension _wishListExtension;
        private void LoadBusiness()
        {
            _wishListExtension = new WishListExtension();
            _users = new Data.Entity.Users(new UserExtension().SelectUser("Email", User.Identity.Name).Rows[0]);
            var list = _wishListExtension.SelectWishedBusinesses(_users.UserId);
            grdWishContent.DataSource = list;
            grdWishContent.DataBind();
            upWishedBusiness.Update();
        }
        protected void btnRemove_Click(object sender, EventArgs e)
        {
            var lnkBtn = (LinkButton)sender;
            _wishListExtension = new WishListExtension();
            _users = new Data.Entity.Users(new UserExtension().SelectUser("Email", User.Identity.Name).Rows[0]);
            int businessId = int.Parse(lnkBtn.CommandArgument);
            int userId = _users.UserId;
            _wishListExtension.RemoveFromWishList(userId, businessId);
            LoadBusiness();
        }

        protected void grdContent_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var link = (HyperLink)e.Row.FindControl("btnName");
                link.NavigateUrl = "~/Place.aspx?id=" + grdWishContent.DataKeys[e.Row.RowIndex].Value;
                link.Attributes["target"] = "new";
            }

        }
    }
}
